/*
   Copyright (c) 2011 Mizar Tools Contributors (mizartools.org)

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/
/*  Contributors :
 *	2011-03-20 Marco Riccardi - initial implementation
 *  
 */
package org.mizartools.example.test;

import java.io.File;

import org.mizartools.system.Error;
import org.mizartools.system.MessageFile;
import org.mizartools.utility.SystemHost;
import org.mizartools.utility.UtilityFile;

public class FileMizarMsg {

	private FileMizarMsg(){}
	
	private static String textFileMizarMsg(){
		String ret = SystemHost.lineTerminator;
		StringBuffer sb = new StringBuffer("");
		for (String s : MessageFile.getHeaderList()){
			sb.append(s);
			sb.append(ret);
		};
		for (Error r: MessageFile.getErrorList()){
			sb.append(r.toRecordInFile());
		}
		sb.append("#");
		sb.append(ret);
		sb.append(ret);
		return sb.toString();
	}

	public static String check(){
		StringBuffer sb = new StringBuffer("");
    	String path = null;
    	String fileName = null;
    	String text = null;
    	String textParsed = null;
		try {
			path = System.getenv("MIZFILES");
			fileName = "mizar.msg";
			text = UtilityFile.readFile(new File(path, fileName));
			textParsed = textFileMizarMsg();
    		if (!text.equals(textParsed)) {
    			sb.append("\n");
    			sb.append("ORIGINAL START\n");
    			sb.append(text + "\n");
    			sb.append("ORIGINAL END\n");
    			
    			sb.append("\n");
    			sb.append("PARSED START\n");
    			sb.append(textParsed + "\n");
    			sb.append("PARSED END\n");
    		}
		} 
		catch (Exception e) {
			sb.append(e.toString());
		}
		return sb.toString();
	}

}
